package com.power.powercash;

import com.db4o.query.Predicate;

/**
 *
 * @author f6036477
 */
public class ConsultaDouble extends Predicate<Double> implements CompareDouble
{

  private CompareDoubleMethod compare;

  private double dd, smaller;

  private boolean empty = false;


  public ConsultaDouble()
  {
    compare = COMPARE_EQUALS;
    dd = 0;
    smaller = 0;
  }


  public ConsultaDouble(double d)
  {
    this();
    dd = d;
    smaller = 0;
  }


  public double getDouble()
  {
    return dd;
  }


  public void setDouble(double d)
  {
    dd = d;
  }


  public double getSmallerDouble()
  {
    return smaller;
  }


  public void setSmallerDouble(double d)
  {
    smaller = d;
  }


  public void setEmptyQuery(boolean emptyQuery)
  {
    empty = emptyQuery;
  }


  public boolean isEmptyQuery()
  {
    return empty;
  }


  @Override
  public boolean match(Double d)
  {
    if(d != null && empty) return true;
    return this.match(dd, d);
  }

  @Override
  public CompareDoubleMethod getCompareDoubleMethod()
  {
    return compare;
  }

  @Override
  public void setCompareDoubleMethod(CompareDoubleMethod c)
  {
    compare = c;
  }


  @Override
  public boolean match(double d1, double d2)
  {
    if(compare == COMPARE_EQUALS)
      return d1 == d2;
    else if(compare == COMPARE_BIGGER)
      return d1 > d2;
    else if(compare == COMPARE_BETWEEN)
      return d1 < d2;
    else
      return match(smaller, d1, d2);
  }

  @Override
  public boolean match(double d1, double d, double d2)
  {
    return d1 < d && d < d2;
  }

}
